package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthModuleModel;
import com.snake.springboot.authority.api.service.AuthModuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类 {@code AuthModuleController}  <br> .
 * <p>权限管理-系统模块
 * 创建时间：2024/5/30 17:19
 *
 * @author Yzhui
 * @see
 */

@Api(tags = "权限管理-系统模块")
@RestController
@RequestMapping("/auth/module")
public class AuthModuleController {

    private AuthModuleService authModuleService;

    @Autowired
    public AuthModuleController(AuthModuleService authModuleService) {
        this.authModuleService = authModuleService;
    }

    @ApiOperation("添加系统模块")
    @PostMapping("/add")
    public ResponseResult<AuthModuleModel> addAuthModule(
            @ApiParam(name = "权限系统模块入参", value = "传入json格式", required = true)
            @RequestBody AuthModuleModel model) throws Exception {
        AuthModuleModel result = authModuleService.addModule(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改系统模块")
    @PostMapping("/modify")
    public ResponseResult<AuthModuleModel> modifyAuthModule(
            @ApiParam(name = "权限系统模块入参", value = "传入json格式", required = true)
            @RequestBody AuthModuleModel model) throws Exception {
        authModuleService.modifyModule(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除系统模块")
    @GetMapping("/remove/{moduleid}")
    public ResponseResult<Object> removeAuthModule(
            @ApiParam(name = "权限系统模块ID", value = "传入json格式", required = true)
            @PathVariable("moduleid") String moduleId) {
        authModuleService.removeModule(moduleId);
        return ResponseResultFactory.ucc("删除成功！");
    }

    @ApiOperation("查询系统模块详情")
    @GetMapping("/query/{moduleid}")
    public ResponseResult<AuthModuleModel> querySingleAuthModule(
            @ApiParam(name = "权限系统模块ID", value = "传入json格式", required = true)
            @PathVariable("moduleid") String moduleId) {
        AuthModuleModel result = authModuleService.querySingleModule(moduleId);
        return ResponseResultFactory.ucc("删除成功！", result);
    }

    @ApiOperation("查询系统模块列表")
    @PostMapping("/list")
    public ResponseResult<List<AuthModuleModel>> queryAuthModulelist(
            @ApiParam(name = "查询参数", value = "传入json格式", required = true)
            @RequestBody AuthModuleModel params) throws Exception {
        List<AuthModuleModel> result = authModuleService.queryModuleList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

}
